import 'package:flutter/material.dart';
import 'package:my_demo_flutter/pages/pageview_test_page.dart';
import 'package:my_demo_flutter/pages/photo_view_test_page.dart';
import 'package:my_demo_flutter/pages/test0216.dart';
import '../my_base_lib/base_lib.dart';
import 'animation_test_page.dart';
import 'dio_test_page.dart';
import 'fijk_player_test_page.dart';

class MainPage extends StatefulWidget {
  static String routeName = "/MainPage";

  MainPage({Key? key}) : super(key: key);

  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends BaseWidgetState<MainPage> {

  @override
  Widget build(BuildContext context) {

    items = [
      ItemData("PageView测试", () {
        Navigator.of(context).pushNamed(PageViewTestPage.routeName);
      }),
      ItemData("PhotoView插件", () {
        Navigator.of(context).pushNamed(PhotoViewTestPage.routeName,arguments: {"aaa":123});
      }),
      ItemData("Dio插件网络操作", () {
        Navigator.of(context).pushNamed(DioTestPage.routeName);
      }),
      ItemData("Fijk播放器使用", () {
        Navigator.of(context).pushNamed(FijkPlayerTestPage.routeName);
      }),
      ItemData("动画测试", () {
        Navigator.of(context).pushNamed(AnimationTestPage.routeName);
      }),
      ItemData("下拉刷新底部加载更多测试", () {
        Navigator.of(context).pushNamed(RefreshAndLoadMorePage.routeName);
      }),

    ];
    
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: const Text("测试demo"),
        centerTitle: true,
        shadowColor: Colors.transparent,
        backgroundColor: Colors.greenAccent,
        elevation: 0,
      ),
      body: GridView.builder(
        itemCount: items.length,
        padding: const EdgeInsets.all(10),
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            childAspectRatio: 3,
            mainAxisSpacing: 10,
            crossAxisSpacing: 10,
            crossAxisCount: 3),
        itemBuilder: (BuildContext context, int index) {
          return _getItemView(index);
        },
      ),
    );
  }

  Widget _getItemView(int index) {
    ItemData itemData = items[index];
    return GestureDetector(
      onTap:itemData.onPress,
      child: Container(
        alignment: Alignment.center,
        decoration: const BoxDecoration(
            color: Colors.grey,
            borderRadius: BorderRadius.all(Radius.circular(10))),
        child: Text(
          itemData.text,
          style: const TextStyle(color: Colors.black87, fontSize: 12),
        ),
      ),
    );
  }
  

  late List<ItemData> items;
}

class ItemData {
  String text;
  void Function()  onPress;

  ItemData(this.text, this.onPress);
}
